# users/admin.py

from django.contrib import admin
from .models import EmailVerification, User, UserProfile, DailyActivity, Avatar
from datetime import timedelta

@admin.register(EmailVerification)
class EmailVerificationAdmin(admin.ModelAdmin):
    list_display = ('email', 'code', 'created_at', 'expires_at', 'is_expired_display')

    def expires_at(self, obj):
        return obj.created_at + timedelta(minutes=10)
    expires_at.short_description = 'Expires At'

    def is_expired_display(self, obj):
        return obj.is_expired()
    is_expired_display.boolean = True
    is_expired_display.short_description = 'Is Expired'

@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    list_display = ('username', 'email', 'is_verified', 'is_staff')
    search_fields = ('username', 'email')
    list_filter = ('is_verified', 'is_staff')

@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('user', 'daily_check_in', 'consecutive_login_days', 'last_login_date', 'is_avatar_approved')
    search_fields = ('user__username', 'user__email')
    list_filter = ('is_avatar_approved',)

@admin.register(DailyActivity)
class DailyActivityAdmin(admin.ModelAdmin):
    list_display = ('user', 'date', 'words_learned', 'is_logged_in', 'is_words_learned')
    search_fields = ('user__username', 'user__email')
    list_filter = ('is_logged_in', 'is_words_learned')

@admin.register(Avatar)
class AvatarAdmin(admin.ModelAdmin):
    list_display = ('name', 'image')
    search_fields = ('name',)
